//
//  CouponListCell.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/16.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "CouponListCell.h"
@interface CouponListCell()

@property(nonatomic,strong)UILabel *title;
@property(nonatomic,strong)UILabel *price;
@property(nonatomic,strong)UILabel *qty;
@property(nonatomic,strong)UILabel *beginDate;
@property(nonatomic,strong)UILabel *endDate;
@property(nonatomic,strong)UILabel *imageUrl;
@property(nonatomic,strong)UILabel *imageUrlFull;
@property(nonatomic,strong)UILabel *useLimitAmt;
@property(nonatomic,strong)UILabel *lineLabel;


@end
@implementation CouponListCell
@synthesize Delegate;
- (void)awakeFromNib {
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
    }
    
    return self;
    
}
-(void)createView
{
    UILabel*qLabel=[[UILabel alloc]initWithFrame:CGRectMake(20, 20, 120, 16)];
    qLabel.font=[UIFont systemFontOfSize:15];
    qLabel.textColor=[UIColor blackColor];
    qLabel.alpha=0.3;
    qLabel.text=@"优惠券";
    [self addSubview:qLabel];
    _price=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 120, 120)];
    _price.font=[UIFont boldSystemFontOfSize:42];
    _price.textColor=[UIColor whiteColor];
    _price.textAlignment=NSTextAlignmentCenter;
    [self addSubview:_price];
    _qty=[[UILabel alloc]initWithFrame:CGRectMake(10, 105, 120, 12)];
    _qty.font=[UIFont boldSystemFontOfSize:9];
    _qty.textColor=[UIColor whiteColor];
    _qty.alpha=0.5;
    _qty.textAlignment=NSTextAlignmentCenter;
    [self addSubview:_qty];
    _title=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-200, 10+43, 150, 16)];
    _title.font=[UIFont boldSystemFontOfSize:16];
    _title.textColor=[UIColor whiteColor];
    _title.textAlignment=NSTextAlignmentRight;
    [self addSubview:_title];
    _share=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-40, 10, 30, 30)];
    [self addSubview:_share];

    _useLimitAmt=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-220, 10+43+16+6, 170, 16)];
    _useLimitAmt.font=[UIFont boldSystemFontOfSize:14];
    _useLimitAmt.textColor=[UIColor whiteColor];
    _useLimitAmt.alpha=0.8;
    _useLimitAmt.textAlignment=NSTextAlignmentRight;
    [self addSubview:_useLimitAmt];
    _beginDate=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-220, 105, 190, 12)];
    _beginDate.font=[UIFont boldSystemFontOfSize:9];
    _beginDate.textColor=[UIColor whiteColor];
    _beginDate.alpha=0.5;
    _beginDate.textAlignment=NSTextAlignmentRight;
    [self addSubview:_beginDate];
    
    UIImageView*dian=[[UIImageView alloc]initWithFrame:CGRectMake(127, 10, 6, 120)];
    dian.image=[UIImage imageNamed:@"youhuiquanxuxian"];
    [self addSubview:dian];
    
}

-(void)share:(UIButton*)sender{
    
    NSLog(@"-----%ld",sender.tag);
    [Delegate share:[NSString stringWithFormat:@"%ld",  sender.tag]];
    
    
}

-(void)setMCouponListModel:(MCouponListModel *)MCouponListModel
{
    UIView *ditu=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 120, 120)];
    ditu.backgroundColor=[UIColor colorWithRed:109/255.0 green:168/255.0 blue:33/255.0 alpha:1.0];
    [self addSubview:ditu];
    
    UIView *ditu1=[[UIView alloc]initWithFrame:CGRectMake(ditu.right, 10, ScreenWidth-140, 120)];
    ditu1.backgroundColor=luseColor;
    [self addSubview:ditu1];
    [self createView];
    [self setViewAutoLayout];
    
   
    if ([[NSString stringWithFormat:@"%@",MCouponListModel.isUsed] isEqualToString:@"0"]) {
        self.saveAccount=YES;
        [_share setBackgroundImage:[UIImage imageNamed: @""] forState:UIControlStateNormal];
    }else{
      self.saveAccount=NO;
     [_share setBackgroundImage:[UIImage imageNamed:@"gouxuan"] forState:UIControlStateNormal];
    }
   
    if ([[NSString stringWithFormat:@"%@",MCouponListModel.couponType] isEqualToString:@"1"]) {
         self.price.text=[NSString stringWithFormat:@"%@",  MCouponListModel.discount];
    }else{
     self.price.text=[NSString stringWithFormat:@"%@",  MCouponListModel.price];
    }
   
    self.title.text=[NSString stringWithFormat:@"%@",  MCouponListModel.title];
    self.qty.text=[NSString stringWithFormat:@"发放数量 %@",MCouponListModel.qty];
    self.useLimitAmt.text=[NSString stringWithFormat:@"用券的最低金额 ¥ %@",MCouponListModel.useLimitAmt];
    NSRange range={0,10};
    NSString* string =[[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",MCouponListModel.beginDate]] substringWithRange:range];
    NSRange range1={0,10};
    NSString* string1 =[[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",MCouponListModel.endDate]] substringWithRange:range1];
    self.beginDate.text=[NSString stringWithFormat:@"有效期 %@~%@",string,string1];
  
}
-(void)setHistoricalRecordModel:(HistoricalRecordModel *)HistoricalRecordModel{
    UIView *ditu=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 120, 120)];
    ditu.backgroundColor=[UIColor colorWithRed:214/255.0 green:214/255.0 blue:214/255.0 alpha:1.0];
    [self addSubview:ditu];
    
    UIView *ditu1=[[UIView alloc]initWithFrame:CGRectMake(ditu.right, 10, ScreenWidth-140, 120)];
    ditu1.backgroundColor=[UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0];
    [self addSubview:ditu1];
    [self createView];
    [self setViewAutoLayout];
    _share=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-169/2-10, 10, 169/2, 147/2)];
    if([[NSString stringWithFormat:@"%@", HistoricalRecordModel.isExpire] isEqualToString:@"N"]) {
        
        if ( [[NSString stringWithFormat:@"%@", HistoricalRecordModel.isUsed] isEqualToString:@"1" ]) {
              [_share setBackgroundImage:[UIImage imageNamed: @"yishiyong"] forState:UIControlStateNormal];
        }
        if ( [[NSString stringWithFormat:@"%@", HistoricalRecordModel.isUsed] isEqualToString:@"2" ]) {
            [_share setBackgroundImage:[UIImage imageNamed: @"yihexiao"] forState:UIControlStateNormal];}

    }else{
    [_share setBackgroundImage:[UIImage imageNamed: @"yiguoqi"] forState:UIControlStateNormal];
    
    }
      [self addSubview:_share];
    
    if ([[NSString stringWithFormat:@"%@",HistoricalRecordModel.couponType] isEqualToString:@"1"]) {
        self.price.text=[NSString stringWithFormat:@"%@",  HistoricalRecordModel.discount];
    }else{
        self.price.text=[NSString stringWithFormat:@"%@",  HistoricalRecordModel.price];
    }
    self.title.text=[NSString stringWithFormat:@"%@",  HistoricalRecordModel.title];
    self.qty.text=[NSString stringWithFormat:@"发放数量 %@",HistoricalRecordModel.qty];
    self.useLimitAmt.text=[NSString stringWithFormat:@"用券的最低金额 ¥ %@",HistoricalRecordModel.useLimitAmt];
    NSRange range={0,10};
    NSString* string =[[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",HistoricalRecordModel.beginDate]] substringWithRange:range];
    NSRange range1={0,10};
    NSString* string1 =[[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",HistoricalRecordModel.endDate]] substringWithRange:range1];
    self.beginDate.text=[NSString stringWithFormat:@"有效期 %@~%@",string,string1];

}
-(void)setModel:(CouponListModel *)model
{
    UIView *ditu=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 120, 120)];
    ditu.backgroundColor=[UIColor colorWithRed:109/255.0 green:168/255.0 blue:33/255.0 alpha:1.0];
    [self addSubview:ditu];
    
    UIView *ditu1=[[UIView alloc]initWithFrame:CGRectMake(ditu.right, 10, ScreenWidth-140, 120)];
    ditu1.backgroundColor=luseColor;
    [self addSubview:ditu1];
    [self createView];
    [self setViewAutoLayout];
    _share=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-70, 10, 60, 60)];
    [_share setBackgroundImage:[UIImage imageNamed: @"fenxiang-youhuiquan"] forState:UIControlStateNormal];
    [_share addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    _share.tag=self.index.intValue;
    [self addSubview:_share];
    
    if ([[NSString stringWithFormat:@"%@",model.couponType] isEqualToString:@"1"]) {
        self.price.text=[NSString stringWithFormat:@"%@",  model.discount];
    }else{
        self.price.text=[NSString stringWithFormat:@"%@",  model.price];
    }
    self.title.text=[NSString stringWithFormat:@"%@",  model.title];
    self.qty.text=[NSString stringWithFormat:@"发放数量 %@",model.qty];
    self.useLimitAmt.text=[NSString stringWithFormat:@"用券的最低金额 ¥ %@",model.useLimitAmt];
    NSRange range={0,10};
    NSString* string =[[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",model.beginDate]] substringWithRange:range];
    NSRange range1={0,10};
    NSString* string1 =[[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",model.endDate]] substringWithRange:range1];
    self.beginDate.text=[NSString stringWithFormat:@"有效期 %@~%@",string,string1];
    
}

-(void)setViewAutoLayout
{
    //    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.mas_left).with.offset(15) ;
    //        make.height.equalTo(@16);
    //        make.top.equalTo(self.mas_top).with.offset(25);
    //    }];
    //
    //    [self.seximage mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.userName.mas_right).with.offset(3);
    //        make.width.equalTo(@20);
    //
    //        make.height.equalTo(@20);
    //
    //        make.top.equalTo(self.mas_top).with.offset(25);
    //    }];
    //    [self.integral mas_makeConstraints:^(MASConstraintMaker *make) {
    //
    //        make.left.equalTo(self.seximage.mas_right).with.offset(15);
    //
    //        make.height.equalTo(@14);
    //
    //        make.centerY.equalTo(self.seximage.mas_centerY) ;
    //    }];
    //
    //    [self.integral1 mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.integral.mas_right).with.offset(3);
    //        make.height.equalTo(@14);
    //
    //        make.centerY.equalTo(self.seximage.mas_centerY) ;
    //
    //    }];
    //
    //
    //    [self.source mas_makeConstraints:^(MASConstraintMaker *make) {
    //
    //        make.left.equalTo(self.mas_left).with.offset(15) ;
    //        make.height.equalTo(@14);
    //        make.top.equalTo(self.userName.mas_bottom).with.offset(15);
    //    }];
    //
    //    [self.source1 mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.source.mas_right).with.offset(3);
    //        make.height.equalTo(@14);
    //
    //        make.centerY.equalTo(self.source.mas_centerY) ;
    //
    //    }];
    //    [self.createDate mas_makeConstraints:^(MASConstraintMaker *make) {
    //
    //        make.left.equalTo(self.source1.mas_right).with.offset(15);
    //
    //        make.height.equalTo(@14);
    //
    //        make.centerY.equalTo(self.source1.mas_centerY) ;
    //    }];
    //
    //    [self.createDate1 mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.createDate.mas_right).with.offset(3);
    //        make.height.equalTo(@14);
    //
    //        make.centerY.equalTo(self.createDate.mas_centerY) ;
    //
    //    }];
    //
    //
    //    [self.address mas_makeConstraints:^(MASConstraintMaker *make) {
    //
    //        make.left.equalTo(self.mas_left).with.offset(15) ;
    //        make.height.equalTo(@14);
    //        make.top.equalTo(self.createDate1.mas_bottom).with.offset(5);
    //    }];
    //
    //    [self.address1 mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.address.mas_right).with.offset(3);
    //        make.height.equalTo(@14);
    //
    //        make.centerY.equalTo(self.address.mas_centerY) ;
    //
    //    }];
    //
    //
    //
    //    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.mas_left).with.offset(10);
    //        make.right.equalTo(self.mas_right).with.offset(-10) ;
    //        
    //        make.height.equalTo(@1);
    //        
    //        make.top.equalTo(@108).with.offset(0);
    //    }];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
